﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.Entity;
using System.Data.SqlClient;
using System.Data;

namespace Business.Dal
{
  public  class ParaProvider:Provider<ParaCins>
    {
        public override bool Insert(ParaCins tObject)
        {
            bool returnValue = false;

            SqlCommand cmd = new SqlCommand("ParaCinsiEkle");
            cmd.Parameters.Add("@ParaCinsiID", SqlDbType.Int).Value = tObject.ParaCinsiID;
            cmd.Parameters.Add("@ParaCinsi", SqlDbType.NVarChar).Value = tObject.ParaCinsi;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = Tools.Connection();
            Tools.Open();
            cmd.ExecuteNonQuery();
            returnValue = true;

            return returnValue;
            /// test
        }

        public override bool Update(ParaCins tObject)
        {
            bool returnValue = false;

            SqlCommand cmd = new SqlCommand("ParaCinsiGuncelle");
            cmd.Parameters.Add("@ParaCinsiID", SqlDbType.Int).Value = tObject.ParaCinsiID;
            cmd.Parameters.Add("@ParaCinsi", SqlDbType.NVarChar).Value = tObject.ParaCinsi;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = Tools.Connection();
            Tools.Open();
            returnValue = Convert.ToBoolean(cmd.ExecuteNonQuery());

            return returnValue;
        }

        public override bool Delete(int RecordID)
        {
            bool returnValue = false;

            SqlCommand cmd = new SqlCommand("ParaSil");
            cmd.Parameters.Add("@ParaCinsiID", SqlDbType.Int).Value = RecordID;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = Tools.Connection();
            Tools.Open();
            returnValue = Convert.ToBoolean(cmd.ExecuteNonQuery());

            return returnValue;
        }

        public List<ParaCins> GetAllRows()
        {

            List<ParaCins> returnValue = new List<ParaCins>();

            SqlCommand cmd = new SqlCommand("ParalariGetir");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = Tools.Connection();
            SqlDataReader dr;
            Tools.Open();
            dr = cmd.ExecuteReader();

            //dr.Read();

            while (dr.Read())
            {
                ParaCins p = new ParaCins();
                // veritananından null gelebilecek kolonlar için bir if yzildi int değer null gelirse geriye 0 değerini döndürmesi sağlandı 
                p.ParaCinsi = dr["ParaCinsi"] is DBNull ? String.Empty : dr["ParaCinsi"].ToString();
                p.ParaCinsiID = dr["ParaCinsiID"] is DBNull ? 0 : Convert.ToInt32(dr["ParaCinsiID"]);

                returnValue.Add(p);
            }

            dr.Dispose();

            return returnValue;

        }

    }
}
